package com.sl.diary.adapter;

import java.util.List;

import com.sl.diary.adapter.TravelItemAdapter.TravelItemAdapterEventCallback;
import com.sl.diary.model.TourModel;
import com.sl.diary.R;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ItineraryItemAdapter extends ArrayAdapter<TourModel> {

	private final Context context;
	private List<TourModel> tours = null;

	public ItineraryItemAdapter(Context context, int textViewResourceId,
			List<TourModel> objects) {

		super(context, textViewResourceId, objects);
		this.context = context;
		this.tours = objects;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			LayoutInflater layoutInflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertView = layoutInflater.inflate(
					R.layout.a004_travel_itinerary_row, null);
		}

		TourModel tour = tours.get(position);
		convertView.setTag(tour.getId());

		ImageView img_tour = (ImageView) convertView
				.findViewById(R.id.img_itinerary_tour_type);
		img_tour.setImageDrawable(this.getTourIconByType(tour.getType()));

		TextView tv_tour_name = (TextView) convertView
				.findViewById(R.id.tv_itinerary_tour_name);
		tv_tour_name.setText(tour.getName());

		return convertView;
	}

	private Drawable getTourIconByType(int type) {
		Drawable icon = null;
		switch (type) {
		case 1:
			icon = context.getResources()
					.getDrawable(R.drawable.icon_geo_black);
			break;
		case 2:
			icon = context.getResources().getDrawable(R.drawable.icon_tour_black);
			break;
		case 3:
			icon = context.getResources().getDrawable(R.drawable.icon_area_black);
			break;
		}
		return icon;
	}
}
